using DslCrossModelFramework.Environment;
using Microsoft.VisualStudio.Modeling;
using DslCrossModelFramework.ModelTraversal;

namespace DslCrossModelFramework.ModelRelationship {
    /// <summary>
    /// Filters out elements that cannot be referenced
    /// </summary>
    public class CanReferenceModelElementFilter : ModelElementFilterBase {
        /// <summary>
        /// Determines whether the specified model element is valid for this filter.
        /// </summary>
        /// <param name="modelElement">The model element.</param>
        /// <returns>
        /// 	<c>true</c> if the specified model element is valid for this filter; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsValid(ModelElement modelElement) {
            if (modelElement is ICrossModelProxyElement && (((ICrossModelProxyElement)modelElement).TargetPath == null || ((ICrossModelProxyElement)modelElement).TargetPath.Count == 0)){
                return false;
            }
            return
                EnvironmentConfiguration.Current.GetModelDirectory().CanReferenceModelElement(
                    modelElement.GetDomainClass());
        }
    }
}